<?php

class UserStatus extends Model
{
	function UserStatus()
	{
		parent::Model();
	}
	
	function all()
	{
		$sql = 'SELECT s.id, s.code, s.label, COUNT(u.id) AS user_count
		        FROM user_status s
		        LEFT JOIN user u on (u.status_id = s.id AND u.active = 1)
		        GROUP BY s.id';
		$query = $this->db->query($sql);
		return $query->result();
	}
	
	function get_id_by_code($code)
	{
		$query = $this->db->get_where('user_status', array('code' => $code), 1);
		$result = $query->row();
		return intval($result->id);
	}
	
	function get_by_id($id)
	{
		$query = $this->db->get_where('user_status', array('id' => $id), 1);
		return $query->row();
	}
}
